package com.easy.system.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easy.common.jdbc.PageInfo;
import com.easy.common.web.PagedList;
import com.easy.common.web.message.Message;
import com.easy.system.domain.Lov;
import com.easy.system.service.LovService;

@Controller
@RequestMapping("LovController")
public class LovController {

	@Autowired
	private LovService lovService;

	/**
	 * 跳转到数据字典维护页
	 * 
	 * @return
	 */
	@RequestMapping("goToLovManager")
	public String goToLovManager(String secondMenuId,HttpServletRequest request) {
		request.getSession().setAttribute("secondMenuId", secondMenuId);
		return "system/lov";
	}

	/**
	 * 查询现有数据字典
	 * 
	 * @return
	 */
	@RequestMapping("getAllLovs")
	@ResponseBody
	public PagedList<Lov> getAllLovs(PageInfo pageInfo) {
		return lovService.findLovsList(pageInfo);
	}

	/**
	 * 保存指定数据字典
	 * 
	 * @param userinfo
	 * @return
	 */
	@RequestMapping("saveLov")
	@ResponseBody
	public Message saveLov(Lov lov) {
		int count = lovService.saveLov(lov);
		Message msg = new Message();
		if (count != 0) {
			msg.setMsg("success");
		} else {
			msg.setMsg("error");
		}
		return msg;
	}

	/**
	 * 删除条目
	 * 
	 * @param userinfo
	 * @return
	 */
	@RequestMapping("removeLov")
	@ResponseBody
	public Message removeLov(Lov lov, HttpServletRequest request) {
		String oid = request.getParameter("id");
		lov.setOid(oid);
		int count = lovService.removeLov(lov);
		Message msg = new Message();
		if (count != 0) {
			msg.setMsg("success");
		} else {
			msg.setMsg("error");
		}
		return msg;
	}
	
	
	
	
	/**
	 * 根据dictType查询select组件选项
	 * @param lov
	 * @return
	 */
	@RequestMapping("findDictListByDictType")
	@ResponseBody
	public List<Lov> findDictListByDictType(Lov lov){
		return lovService.findDictItems(lov);
	}
}
